package com.admin.system.config;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.annotation.Configuration;

/**
 * @author caixiaofeng
 * @version 1.0
 * @Description: <<>>
 * @company 捷创智能技术有限公司
 * @create 2021-04-16 14:58
 */
@Configuration
public class ApplicationContextConfig implements ApplicationContextAware {
    private static ApplicationContext applicationContext;

    @Override
    public void setApplicationContext(ApplicationContext context) throws BeansException {
        ApplicationContextConfig.applicationContext = context;
    }

    public static <T> T getBean(Class<T> beanName) {
        return applicationContext.getBean(beanName);
        // return applicationContext.getBean(beanName);
    }

    public static Object getBean(String beanName) {
        return applicationContext.getBean(beanName);
        // return applicationContext.getBean(beanName);
    }

    public static ApplicationContext getApplicationContext() {
        return applicationContext;
    }
}
